/**
* 借贷管理  借贷信息
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index/mainAdmin' }">主页</el-breadcrumb-item>
      <el-breadcrumb-item>借贷管理</el-breadcrumb-item>
      <el-breadcrumb-item>借贷信息</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.name" placeholder="输入银行"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>

    <!--列表-->
    <el-table size="small" :data="legalData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" sortable prop="legalId" label="id" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="yeard" label="贷款期限(月)" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="bank" label="贷款银行" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="totalMoney" label="借款金额" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="sumMoney" label="总还款金额" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="textArea" label="贷款用途" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="dateTime" :formatter="formatDate" label="贷款日期" width="150">
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination class="page-box"   layout="total" :total="pageparm.total">
    </el-pagination>

  </div>
</template>

<script>
// 导入请求方法
export default {
  data() {
    return {
      loading: false, //是显示加载
      title: '借贷信息',
      legalData:[],
      // 请求数据参数
      formInline: {
        name:'',
        adminName:'',
        bank: ''
      },
      listData: [], //搜索数据
      // 分页参数
      pageparm: {
        total: 10
      }
    }
  },


  /**
   * 创建完毕
   */
  created() {
    this.getdata()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getdata() {
      this.loading = true
      this.$axios
          .post(`http://localhost:9090/loan/legal/getLegalList`).then(
          response => {
            this.legalData = response.data;
            this.listData = response.data;
            // 分页赋值
            this.pageparm.total = this.legalData.length
            this.loading = false
          }
      )
    },
    //搜索事件
    search() {
      if (this.formInline.name===''){
        this.legalData=this.listData
      }else {
        this.legalData=[]
        this.loading = true
        for (let i=0;i<this.listData.length;i++){
          if (this.listData[i].bank.indexOf(this.formInline.name)!=-1){
            // alert('收到了')
            // console.log(this.listData[i])
            this.legalData.push(this.listData[i])
          }
        }
        this.loading = false
      }
      /*this.getdata(this.formInline)*/
    },
    //日期转换
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property]
      if(data == null) {
        return null
      }
      let dt = new Date(data)
      return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds()
    },

  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

